1 /* 2 * Copyright (C) 2011 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.cache; 18 19 import com.google.common.annotations.Beta; 20 import com.google.common.annotations.GwtCompatible; 21 22 /** 23 * An object that can receive a notification when an entry is removed from a cache. The removal 24 * resulting in notification could have occured to an entry being manually removed or replaced, or 25 * due to eviction resulting from timed expiration, exceeding a maximum size, or garbage 26 * collection. 27 * 28 * <p>An instance may be called concurrently by multiple threads to process different entries. 29 * Implementations of this interface should avoid performing blocking calls or synchronizing on 30 * shared resources. 31 * 32 * @param <K> the most general type of keys this listener can listen for; for 33 * example {@code Object} if any key is acceptable 34 * @param <V> the most general type of values this listener can listen for; for 35 * example {@code Object} if any key is acceptable 36 * @author Charles Fry 37 * @since 10.0 38 */ 39 @Beta 40 @GwtCompatible 41 public interface RemovalListener<K, V> { 42 /** 43 * Notifies the listener that a removal occurred at some point in the past. 44 */ 45 // Technically should accept RemovalNotification<? extends K, ? extends V>, but because 46 // RemovalNotification is guaranteed covariant, let's make users' lives simpler. 47 void onRemoval(RemovalNotification<K, V> notification); 48 }